﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using model;
using Bll;
using System.Web.Security;

public partial class Registers : System.Web.UI.Page
{
    StudentBll bll = new StudentBll();
    ResumeBll rbll = new ResumeBll();
    protected void Page_Load(object sender, EventArgs e)
    {
        txtSbirth.Attributes.Add("onfocus","javascript:document.getElementById('ca').style.display=\"block\";");
    }
    protected void btnReg_Click(object sender, EventArgs e)
    {
        Student student = new Student();
        if (txtSpwd1.Text == txtSpwd2.Text)
        {
            try
            {
                string pwd = txtSpwd1.Text.Trim();
                pwd=FormsAuthentication.HashPasswordForStoringInConfigFile(pwd,"MD5");
                student.Sno = txtSno.Text.Trim();
                student.Spwd = pwd;
                student.Sname = txtSname.Text;
                student.Smajor = ddlMajor.Text;
                student.Sclass = txtSclass.Text;
                student.Sbirth = Convert.ToDateTime(txtSbirth.Text);
                student.Go = ddlSgo.Text;
                if (RdMale.Checked == true)
                {
                    student.Ssex = RdMale.Text;
                }
                else
                {
                    student.Ssex = rdFemale.Text;
                }
                bll.ZhuCe(student);
                rbll.Insert(txtSno.Text);
                Session["username"] = txtSname.Text;
                Session["userid"] = txtSno.Text;
                Session["usergroup"] = "student";
                Response.Write("<script>alert('注册成功！');location.href='Default.aspx';</script>");
            }
            catch (Exception ex)
            {
                string js = "<script>alert('" + ex.Message + "');</script>";
                Response.Write(js);
            }
        }
        else
        {
            string str="<script>alert('两次密码不一致！');</script>";
            Response.Write(str);
        }
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        txtSbirth.Text = Calendar1.SelectedDate.ToLongDateString();
        Calendar1.Attributes.Add("onblur", "javascript:document.getElementById('Calendar1').style.display=\"none\";");
    }
    protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
    {
        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "key", "document.getElementById('ca').style.display=\"block\";", true);
    }
}